<?php
class Classes extends Zend_Db_Table{
    	protected $_name ="class";
	protected $_primary = 'class_id';

    public function getTopClasses(){
          $select = $this->select();
          $select->limit('10');
          $select->order('class_id desc');
          return $this->fetchAll($select)->toArray();
    }
    //根据传来的class_id的数组，查询出所有class
    public  function getAllClassInArray($array){

            $where=" class_id in (".implode(',',$array).")";
            $select = $this->select();
            $select->where($where);
            $select->order('class_id desc');
            $sql = $select->__toString();
          //  return $sql;
            return $this->fetchAll($select)->toArray();
    }

       // 查询所有class
    public function getAllClasses($page,$perpage,$teacher_id,$search_name,$search_start_time,$search_location){
          $where = "1=1";
          if($teacher_id!=""){
              $where.= " and teacher_id=$teacher_id";
          }
          if($search_name!=""){
              $where.=" and name like '%$search_name%'";
          }
          if($search_start_time!=""){
              $where.=" and start_time='$search_start_time'";
          }
          if($search_location!=""){
              $where.=" and location like '%$search_location%'";
          }
          $select = $this->select();
          $select->where($where);
          if($page!=""){
          $select->limitPage($page,$perpage);
          }
         // return $select->__toString();
          $select->order('class_id desc');
          return $this->fetchAll($select)->toArray();
    }
    
    public function getAllClassesexcel(){
          $where = "1=1";

          $select = $this->select();
          $select->where($where);
         // return $select->__toString();
          $select->order('class_id asc');
          return $this->fetchAll($select)->toArray();
    }

    //根据class_id 查询class
    public function getclassByclass_id($class_id){
          $select = $this->select();
          $select->where("class_id=".$class_id);
          return $this->fetchAll($select)->toArray();
    }
	
	//根据class_name 查询class
    public function getclassByclass_name($class_name){
          $select = $this->select();
          $select->where("name='".$class_name."'");
          return $this->fetchAll($select)->toArray();
    }
	
    
   public function getclasslikeclass_name($class_name){
          $select = $this->select();
          $select->where("name like'%".$class_name."%'");
          return $this->fetchAll($select)->toArray();
    }
    
     //根据teacher_id 查询class
    public function getclassByteacher_id($teacher_id){
          $select = $this->select();
          $select->where("teacher_id=".$teacher_id);
          return $this->fetchAll($select)->toArray();
    }

 //更新class
    public function updateclassByclass_id($array,$class_id){

		$db = $this->getAdapter();
		$where=$db->quoteInto('class_id = ?', $class_id);
		$this->update($array, $where);
                return true;
	}
//删除class
     public function delclassByclass_id($class_id){
          $where = 'class_id = '. $class_id;
         $this->delete($where);
         return true;
    }
	
	public function getClassByTime($time1, $time2){
		$select = $this->select();
        $select->where("start_time>=".$time1);
		$select->where("start_time<".$time2);
        return $this->fetchAll($select)->toArray();
	}
	
	public function getClassByTimeType($time1,$time2,$category){
		$select = $this->select();
		$select->where("category=".$category);
        $select->where("start_time>=".$time1);
		$select->where("start_time<".$time2);
		return $this->fetchAll($select)->toArray();
	}
	
	public function getClassOrderIncome(){
		$select = $this->select();
		$select->order("income desc");
		$select->limit(10);
		return $this->fetchAll($select)->toArray();
	}
}
?>
